04. Getting an API Key

L4 A03 Getting An API Key

Reference Documentation

Get an API Key

  1. Open the debug version of the google_maps_api.xml file. The file includes a comment with a long URL. The URL's parameters include specific information about your app.
  2. Copy and paste the URL into a browser.
  3. Follow the prompts to create a project in the Google API Console. Because of the parameters in the provided URL, the API Console knows to automatically enable the Google Maps Android API.
  4. Create an API key and click Restrict Key to restrict the key's use to Android apps. The generated API key should start with AIza.
  5. In the google_maps_api.xml file, paste the key into the google_maps_key string where it says YOUR_KEY_HERE.
  6. Run your app. You have an embedded map in your activity, with a marker set in Sydney, Australia. (The Sydney marker is part of the template, and you change it later.)

Rename mMap

MapsActivity has a private lateinit var called mMap which is of type GoogleMap. By Kotlin naming conventions you will want to change it to be called map instead.

  1. In MapsActivity, right click on mMap and click Refactor/Rename

  1. Change the variable name to map.
    Notice how all the references to mMap in the onMapReady() function also change to map.